﻿Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim p As New Process()
        p.StartInfo.FileName = "C:\WiFi Share™\Config\start.bat"
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        p.Start()
        p.WaitForExit()
        p.Close()

        Dim Command As String
        Command = "netsh wlan start hostednetwork"
        Shell("cmd /c" & Command, AppWinStyle.Hide, True)
        MessageBox.Show("Hotspot Started")

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim Command As String
        Command = "netsh wlan stop hostednetwork"
        Shell("cmd /c" & Command, AppWinStyle.Hide, True)
        MessageBox.Show("Hotspot Stopped")

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Try
            If My.Computer.FileSystem.DirectoryExists("C:\WiFi Share™\" + "Config\") Then

            Else
                MkDir("C:\WiFi Share™\" + "Config\")
                Dim start As New System.IO.StreamWriter("C:\WiFi Share™\Config\start.bat")
                start.WriteLine("netsh wlan set hostednetwork mode=allow ssid=WiFiShare key=1234567890")
                start.Close()
            End If

        Catch ex As Exception
            MessageBox.Show("WiFiShare cannot create settings. Please make sure you are admin")
        End Try

    End Sub

    Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MsgBox("Are you sure you want to quit? All connections will be terminated.", MsgBoxStyle.Exclamation + MsgBoxStyle.OkCancel, "Warning") = vbOK Then
            Dim Command As String
            Command = "netsh wlan stop hostednetwork"
            Shell("cmd /c" & Command, AppWinStyle.Hide, True)
        Else
            e.Cancel = True
            'Exit Sub
        End If
    End Sub

End Class
